package com.supermap.census.ui;

import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

import com.supermap.census.R;
import com.supermap.census.app.BaseActivity;
import com.supermap.commonlibrary.utils.MyEditUtils;
import com.supermap.commonlibrary.utils.ToastUtil;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * 注册界面
 */
public class RegisterActivity extends BaseActivity {

    @Bind(R.id.return_img)
    ImageView returnImg;
    @Bind(R.id.nickNameEd)
    EditText nickNameEd;
    @Bind(R.id.userNameEd)
    EditText userNameEd;
    @Bind(R.id.passWordEd)
    EditText passWordEd;
    @Bind(R.id.subjectEd)
    EditText subjectEd;
    @Bind(R.id.phoneNumberEd)
    EditText phoneNumberEd;
    @Bind(R.id.emailEd)
    EditText emailEd;
    @Bind(R.id.districtEd)
    EditText districtEd;
    @Bind(R.id.ensureRegisterBtn)
    Button ensureRegisterBtn;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_register;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void doBusiness() {

    }

    @OnClick({R.id.return_img, R.id.ensureRegisterBtn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.return_img:
                finish();
                break;
            case R.id.ensureRegisterBtn:
                /**
                 * 去注册
                 */
                toRegister();
                break;
        }
    }

    /**
     * register account
     */
    private void toRegister() {
        String nickName = MyEditUtils.getStr(nickNameEd);
        String userName = MyEditUtils.getStr(userNameEd);
        String passWord = MyEditUtils.getStr(passWordEd);
        String subject = MyEditUtils.getStr(subjectEd);
        String phoneNumber = MyEditUtils.getStr(phoneNumberEd);
        String email = MyEditUtils.getStr(emailEd);
        String district = MyEditUtils.getStr(districtEd);
        if (TextUtils.isEmpty(nickName)
                || TextUtils.isEmpty(userName)
                || TextUtils.isEmpty(passWord)
                || TextUtils.isEmpty(subject)
                || TextUtils.isEmpty(phoneNumber)
                || TextUtils.isEmpty(email)
                || TextUtils.isEmpty(district)) {
            ToastUtil.showToast(this, "请输入完整的注册信息!");
        } else {
            registerAccount(nickName, userName, passWord, subject, phoneNumber, email, district);
        }

    }

    /**
     * 用户注册
     *
     * @param nickName
     * @param userName
     * @param passWord
     * @param subject
     * @param phoneNumber
     * @param email
     * @param district
     */
    private void registerAccount(String nickName, String userName, String passWord,
                                 String subject, String phoneNumber, String email,
                                 String district) {

    }
}
